package demo.practice.leetcode_base;


import java.util.PriorityQueue;

public class P242 {


    public static void main(String[] args) {
        P242 p242= new P242();
        p242.isAnagram("anagram","nagaram");
    }
    public boolean isAnagram(String s, String t) {
        /*PriorityQueue<Character> queue1= new PriorityQueue((o1,o2)->(char)o1-(char)o2);
        PriorityQueue<Character> queue2= new PriorityQueue((o1,o2)->(char)o1-(char)o2);
        if(s.length()!=t.length())
            return false;
        for(int i=0;i<s.length();i++){
            queue1.add(s.charAt(i));
            queue2.add(t.charAt(i));
        }

        for(int i=0;i<s.length();i++){
            if(!queue1.poll().equals(queue2.poll()))
                return false;
        }

        return true;*/

        if(s.length()!=t.length())
            return false;
        int [] arr= new int[26];
        int [] arr2= new int[26];
        for(int i=0;i<s.length();i++){
            arr[s.charAt(i)-'a']++;
            arr2[t.charAt(i)-'a']++;
        }

        for(int i=0;i<s.length();i++){
            if(arr[s.charAt(i)-'a']!=arr2[s.charAt(i)-'a'])
                return false;
        }
        return true;

    }

}
